<template>
  <el-cascader
    :value="value"
    size="mini"
    :options="list"
    :props="props"
    separator="-"
    @change="changeValue"
  />
</template>

<script>
import { getDashboard } from '@/api/department'
import { transListToTreeData } from '@/utils/index'
export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      list: [], // 返的初始部门列表详情
      props: {
        value: 'id',
        label: 'name'
      }
    }
  },
  created() {
    this.getDashboard()
  },
  methods: {
    async getDashboard() {
      this.list = transListToTreeData(await getDashboard(), 0)
      console.log(this.list)
    },
    changeValue(list) {
      // 取到数组的最后一次
      console.log(list)
      if (list.length > 0) {
        this.$emit('input', list[list.length - 1]) // 将最后一位的id取出来 传出去
      } else {
        this.$emit('input', null) // 如果长度为0 说明值为空
      }
    }
  }
}
</script>

<style>

</style>
